home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / Shell ƒ / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.9 KB  |  77 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        error.c
  4.  
  5. Purpose:    This module handles altering the user when an error has
  6.             occurred.  (If the program is currently in the background,
  7.             we use the Notification Manager to queue a notification
  8.             request and display the alert as soon as we are in the
  9.             foreground -- see main.c, DispatchEvents, case osEvt.)
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "error.h"
  29. #include "main.h"
  30. #include "dialogs.h"
  31. #include "environment.h"
  32.  
  33. NMRec            gMyNotification;
  34. enum ErrorTypes    gPendingResultCode;
  35.  
  36. void HandleError(enum ErrorTypes resultCode, Boolean exitToShell)
  37. /* if we're in the foreground, just get the error string (from the .rsrc file) and
  38.    display the error alert; otherwise, we have to queue it, put up a notification
  39.    (if possible), and wait patiently to come back in the foreground.  (see main.c,
  40.    DispatchEvents(), case osEvt. */
  41. /* All error codes are listed in program globals.h */
  42. {
  43.     Str255            tempStr;
  44.     Handle            myResHand;
  45.     
  46.     /* if there is no error, or the error is that the user cancelled an operation
  47.        in progress, don't display anything; it would only confuse them. */
  48.     if ((resultCode==userCancelErr) || (resultCode==allsWell)) return;
  49.     
  50.     if (gIsInBackground)    /* if program is in background, can't display alert immed. */
  51.     {
  52.         if (gHasNotificationManager)    /* if they don't have notification, f*ck 'em */
  53.         {
  54.             myResHand=GetResource('SICN', 1234);    /* small icon for menu bar flashing */
  55.             gMyNotification.qType=nmType;            /* for more detail on these params, */
  56.             gMyNotification.nmMark=1;                /* see IM Processes, 5-8 */
  57.             gMyNotification.nmIcon=myResHand;
  58.             gMyNotification.nmSound=(Handle)-1L;
  59.             gMyNotification.nmStr=0L;
  60.             gMyNotification.nmResp=0L;
  61.             gMyNotification.nmRefCon=0L;
  62.             NMInstall(&gMyNotification);
  63.         }
  64.         gPendingResultCode=resultCode;                /* remember error code for later */
  65.     }
  66.     else
  67.     {
  68.         GetIndString(tempStr, 129, resultCode);    /* get error string from .rsrc */
  69.         ParamText(tempStr, "\p", "\p", "\p");
  70.         PositionDialog('ALRT', largeAlert);        /* position alert (see dialogs.c) */
  71.         StopAlert(largeAlert, 0L);                /* show it */
  72.     }
  73.     
  74.     if (exitToShell)        /* for fatal errors */
  75.         ExitToShell();
  76. }
  77.